const axios = require('axios')
const { token } = require('../config/config_deafault')

function deleteAricleImage(key) {
    console.log(key);

    return new Promise((resolve, reject) => {
        axios.delete(`http://skypro.afterglow26.cn:28080/api/v1/images/${key}`, {
            headers: {
                Authorization: token,
            }
        }).
            then((res) => {
                console.log(res.data.status === true);
                if (res.data.status === true) {
                    resolve('删除成功: ' + key);
                } else {
                    reject('删除失败: ' + key);
                }
            })
            .catch((error) => {
                reject('删除失败');
            });

    })
}


const DeleteSpecified = (params) => {
    //返回待确认的Promise数组
    const deleteParams = params.map(item => deleteAricleImage(item.imagekey))
    return Promise.all(deleteParams).then((res) => {
        return res
    }).catch((error) => {
        throw error
    })
}

module.exports = { DeleteSpecified }